package com.ruoyi.restaurant.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.restaurant.vo.BillsVo;
import com.ruoyi.restaurant.vo.TableNumsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.restaurant.mapper.SysBillMapper;
import com.ruoyi.restaurant.domain.SysBill;
import com.ruoyi.restaurant.service.ISysBillService;

/**
 * 消费记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-04-18
 */
@Service
public class SysBillServiceImpl implements ISysBillService 
{
    @Autowired
    private SysBillMapper sysBillMapper;

    /**
     * 查询消费记录
     * 
     * @param billId 消费记录主键
     * @return 消费记录
     */
    @Override
    public SysBill selectSysBillByBillId(Long billId)
    {
        return sysBillMapper.selectSysBillByBillId(billId);
    }

    /**
     * 查询消费记录列表
     * 
     * @param sysBill 消费记录
     * @return 消费记录
     */
    @Override
    public List<SysBill> selectSysBillList(SysBill sysBill)
    {
        return sysBillMapper.selectSysBillList(sysBill);
    }

    /**
     * 新增消费记录
     * 
     * @param sysBill 消费记录
     * @return 结果
     */
    @Override
    public int insertSysBill(SysBill sysBill)
    {
        return sysBillMapper.insertSysBill(sysBill);
    }

    /**
     * 修改消费记录
     * 
     * @param sysBill 消费记录
     * @return 结果
     */
    @Override
    public int updateSysBill(SysBill sysBill)
    {
        return sysBillMapper.updateSysBill(sysBill);
    }

    /**
     * 批量删除消费记录
     * 
     * @param billIds 需要删除的消费记录主键
     * @return 结果
     */
    @Override
    public int deleteSysBillByBillIds(Long[] billIds)
    {
        return sysBillMapper.deleteSysBillByBillIds(billIds);
    }

    /**
     * 删除消费记录信息
     * 
     * @param billId 消费记录主键
     * @return 结果
     */
    @Override
    public int deleteSysBillByBillId(Long billId)
    {
        return sysBillMapper.deleteSysBillByBillId(billId);
    }

    /**
     * 统计每张table发生的订单数量
     */
    @Override
    public List<TableNumsVo> CountOrdersByTableId(){
        List<SysBill> billList =this.sysBillMapper.selectSysBillList(new SysBill());
        List<TableNumsVo> tableNumsVoList = new ArrayList<>();
        for(SysBill sysBill :billList){
            TableNumsVo tableNumsVo = new TableNumsVo();
            long count = this.sysBillMapper.countsBillsByDate();
            tableNumsVo.setValue(Math.toIntExact(count));
            tableNumsVoList.add(tableNumsVo);
        }
        return tableNumsVoList;
    }

    /**
     * 统计一周内营业的实际收益
     */
    @Override
    public List<BillsVo> countsBillsByDate(){
        List<SysBill> billList =this.sysBillMapper.selectSysBillList(new SysBill());
        List<BillsVo> billsList = new ArrayList<>();
        for(SysBill bill : billList){
            int value = this.sysBillMapper.countsBillsByDate();
            /**
             * 统计收益部分代码
             */
        }
        return billsList;
    }
}
